package com.luo.ai.assistant.etl;

import org.springframework.ai.document.Document;
import org.springframework.core.io.Resource;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * ETL服务
 *
 * @author luohq
 * @date 2025-01-01 15:21
 */
public interface MyEtlService {

    /**
     * ETL文件批处理
     *
     * @param fileIds the file ids
     * @return fileId and related documents
     */
    Map<String, List<Document>> etlFileBatch(Collection<String> fileIds);

    /**
     * Read resource to Document, transform Document, and write Document
     * <p>
     * 默认实现
     * </p>
     *
     * @param resource the resource
     * @return the list
     */
    List<Document> etl(Resource resource);

    /**
     * Read resource to Document, transform Document, and write Document
     * <p>
     * 默认实现
     * </p>
     *
     * @param resource the resource
     * @param additionalDocumentMetadata the document metadata
     * @return the list
     */
    List<Document> etl(Resource resource, Map<String, Object> additionalDocumentMetadata);

    /**
     * Read resource to Document, transform Document, and write Document
     * <p>
     * 默认实现
     * </p>
     *
     * @param resourceUrl the resource url
     * @return the list
     */
    List<Document> etl(String resourceUrl);

    /**
     * Read resource to Document, transform Document, and write Document
     * <p>
     * 支持自定义实现
     * </p>
     *
     * @param resource           the resource
     * @param readOperation      the read operation
     * @param transformOperation the transform operation
     * @param writeOperation     the write operation
     * @return the list
     */
    List<Document> etlCustom(Resource resource,
                             Function<MyDocumentReader, List<Document>> readOperation,
                             BiFunction<MyDocumentTransformer, List<Document>, List<Document>> transformOperation,
                             BiConsumer<MyDocumentWriter, List<Document>> writeOperation);

    /**
     * Read resource to Document, transform Document, and write Document
     * <p>
     * 支持自定义实现
     * </p>
     *
     * @param resourceUrl        the resource url
     * @param readOperation      the read operation
     * @param transformOperation the transform operation
     * @param writeOperation     the write operation
     * @return the list
     */
    List<Document> etlCustom(String resourceUrl,
                             Function<MyDocumentReader, List<Document>> readOperation,
                             BiFunction<MyDocumentTransformer, List<Document>, List<Document>> transformOperation,
                             BiConsumer<MyDocumentWriter, List<Document>> writeOperation);

}
